<template>
	<view class="content">
		<navbar title='我的订单'>
		</navbar>
		<view class="content">
			<u-sticky offset-top="0">
				<view class="tgou">
					<view class="goulist">
						<view class="gouview" :class="headcurrent==1?'gactive':''" @click="gethead(1)">
							商城订单
						</view>
						<view class="gouview" :class="headcurrent==2?'gactive':''" @click="gethead(2)">
							团购订单
						</view>
					</view>
					<!-- <u-tabs style="width: 100%;" :list="headlist" active-color="#1A1A1A" inactive-color="#666666" :is-scroll="false" :current="headcurrent" @change="change"></u-tabs> -->
				</view>
				<view class="tuanone">
					<u-tabs style="width: 100%;" :list="tablist" active-color="#1A1A1A" inactive-color="#666666" :is-scroll="false" :current="current" @change="change"></u-tabs>
				</view>
				
			</u-sticky>
			<view class="menlist">
				<!-- <view class="nodata">
					<image class="kzt_img_zwsj" src="@/pages_client/static/mine/kzt_img_zwsj.png" mode="" />
					<text>暂无相关订单</text>
				</view> -->
				<view class="oitem" v-for="(item,index) in list" :key="index" @click.stop="getdetail(item)">
					<view class="ohead">
						<image class="icon_sj" src="@/pages_client/static/img/icon_sj.png" mode="" />
						<text class="dianname txt">{{item.shop_name}}</text>
						<text class="dianname txt">{{ item.order_sn }}</text>
						<text class="zt ml">{{item.status_text}}</text>
					</view>
					<view class="olist">
						<view class="onav" v-for="(i,ind) in item.goods_list" :key="ind">
							<image class="tu" :src="ossThree(i.goods_image)" />
							<view class="navright">
								<view class="navone">
									<text class="bt txt">{{i.goods_name}}</text>
									<text class="jia ml">￥{{ i.goods_price }}</text>
								</view>
								<view class="navone mt">
									<text class="btmiao txt">{{ i.goods_sku_name }}</text>
									<text class="btmiao ml">x{{ i.goods_nums }}</text>
								</view>
								<!-- <view class="navone">
									<view class="zheng">正品保障</view>
								</view> -->
								
							</view>
						</view>
					</view>
					<view class="heview">
						<view class="hename">
							<text class="ml">共{{item.goods_nums}}件,合计￥{{item.total_money}}</text>
						</view>
						<view class="hename">
							<view class="btn" v-if="item.status=='0'" @click.stop="getquxiao(item)">取消订单</view>
							<view class="btn fukuan" v-if="item.status=='0'" @click.stop="getpay(item.id)">去付款</view>
							<view class="btn queren" v-if="item.status=='2'" @click.stop="getdelivery(item)">确认收货</view>
						</view>
					</view>
				</view>
				<u-loadmore :status="status" @loadmore="loadmore" />
			</view>
		</view>

		<!-- <view class="botview">
			<view class="tjia">确认</view>
		</view> -->

		<u-popup  v-model="cancelpop" mode="center" width="80%" ref="auth" :mask-close-able="false" :custom="true" :mask-click="false" @close="closecancel">
			<view class="popone">
                <view class="phonenav">
                    <view class="cha" @click="closecancel">
                        <image class="icon_gbcha" src="@/pages_client/static/img/icon_gbicon.png" mode="" />
                    </view>
                    <text class="jiename">取消订单</text>
                    <view class="queli">
						<u-input v-model="des" type="text" placeholder='请输入取消原因' />
                    </view>
                    <view class="dianbtn" @click="temClick">
                        <text class="bm">确认</text>
                    </view>
                    <!-- <text class="kaolv"  @click="closeedit">取消</text> -->
                </view>
                
            </view>
		</u-popup>
	</view>
</template>

<script>
	export default {
		components: {
		},
		data() {
			return {
				tablist: [{
					name: '全部'
				}, {
					name: '待付款'
				}, {
					name: '待发货'
				},{
					name: '待收货'
				}, {
					name: '已完成'
				}],
				current: 0,
				headlist: [{
					name: '商城订单'
				}, {
					name: '团购订单'
				}],
				headcurrent: 1,
				value:1,
				list: [],
				page: 1,
				limit: 10,
				last_page: 1,
				status: "loadmore",
				type:'1',//1 商城订单 2 团购订单
				cancelpop:false,
				des:'',
				popid:''
			}
		},
		onLoad(option) {
			if(option.id){
				this.current = option.id
			}
			this.getList()
		},
		onShow() {
		},
		onReachBottom: function () {
			this.loadmore();
		},
		methods: {
			async getList(){//列表数据
				let status = ''
				if(this.current == 0){
					status = ''
				}else if(this.current == 1){
					status = '0'
				}else if(this.current == 2){
					status = '1'
				}else if(this.current == 3){
					status = '2'
				}else if(this.current == 4){
					status = '3'
				}
				let res = await this.$u.api.ordergetList({
				  limit:this.limit,
				  page:this.page,
				  type:this.headcurrent,
				  status:status//空是全部 0待付款 1待发货 2待收货 3已完成
				});
				this.last_page = res.lastpage
				let list = res.list;
				this.list = this.page == 1 ? list : [...this.list, ...list];	
				if(res.list==''||Number(list.length)<Number(this.limit)||Number(this.page)>Number(this.last_page)){
					this.status = 'nomore';
				}
				
			},
			loadmore() {
				let page = this.page;
				// let last_page = this.last_page;
				if (this.status == 'loadmore') {
					this.page++;
					this.getList();
				}
			},
			getClear(){
				this.list = []
				this.page = 1,
				this.status= "loadmore"
				this.getList()
			},
			gethead(e){
				this.headcurrent = e
				this.current = 0
				this.getnavhead()
				this.getClear()
				
			},
			getnavhead(){
				//监测顶部名字
				if(this.headcurrent == 1){
					this.tablist =  [{
						name: '全部'
					}, {
						name: '待付款'
					}, {
						name: '待发货'
					},{
						name: '待收货'
					}, {
						name: '已完成'
					}]
				}else if(this.headcurrent == 2){
					this.tablist =  [{
						name: '全部'
					}, {
						name: '待付款'
					}, {
						name: '待核销'
					},{
						name: '已核销'
					}]
				}
				this.$forceUpdate()
			},
			closeteam(){
				this.teampopshow = false
			},
			change(index) {
				this.current = index;
				this.getClear()
			},
			getdetail(item){
				this.navrouter('/pages_client/mine/OrderDetail?id='+item.id)
			},
			getquxiao(item){
				this.popid = item.id
				this.cancelpop = true
			},
			async temClick(){
				let res = await this.$u.api.ordercancel({
					order_id:this.popid,
					des:this.des
				});
				this.$u.toast("取消成功");
				this.closecancel()
				this.getClear()
			},
			async getdelivery(item){//确认收货
				let res = await this.$u.api.delivery({
					order_id:item.id
				});
				this.$u.toast("操作成功");
				this.closecancel()
				this.getClear()
			},
			closecancel(){
				this.des = ''
				this.cancelpop = false
			},
			async getpay(id){
				let res = await this.$u.api.getOrderByGoods({
					order_id:id
				});
				uni.requestPayment({
                    appId: res.appid,
                    nonceStr: res.nonceStr,
                    package: res.package,
                    paySign: res.paySign,
                    signType: res.signType,
                    timeStamp: res.timeStamp,
                    success: (e) => {
                        console.log(e)
                        uni.showToast({
                            title: '支付成功',
                            icon: 'success',
                            duration: 2500,
                        })
						setTimeout(() => {
							this.getClear()
						}, 1000);
                    },
                    fail: (e) => {
                        console.log(e)
                        this.$u.toast("支付失败");
						setTimeout(() => {
							this.getClear()
						}, 1000);
                        // uni.switchTab({ url: '/pages/tabbar/my' })
                        // uni.showModal({
                        //     content: "支付失败,原因为: " + e.errMsg,
                        //     showCancel: false
                        // })
                    }
                })
			}
		}
	}
</script>

<style lang="scss" scoped>
	page{
		background-color: #f9f9f9;
	}
	.content{
		background-color: #f9f9f9;
		padding-bottom: 30rpx;
		.tgou{
			background-color: #fff;
			z-index: 10;
			.goulist{
				border: 1rpx solid #483C38;
				width: 80%;
				margin: 0 auto;
				height: 75rpx;
				border-radius: 50rpx;
				display: flex;
				flex-direction: row;

				.gouview{
					width: 50%;
					display: flex;
					align-items: center;
					justify-content: center;
					border-radius: 50rpx;
				}
				.gactive{
					background-color: #483C38;
					color: #fff;
				}
			}
			
		}
		.tuanone{
			background-color: #fff;
			padding: 15rpx 10rpx;
			display: flex;
			flex-direction: row;
			align-items: center;
			width: 100%;
			.tuhead{
				max-width: 80%;
				white-space: nowrap;
				.tuitem{
					padding: 8rpx 20rpx;
					background: #F5F5F5;
					border-radius: 10rpx;
					margin-right: 20rpx;
					font-weight: 500;
					font-size: 26rpx;
					color: #333333;
					display: inline-block;
				}
				.tactive{
					background: #52443B;
					color: #fff;
				}
			}
			.icon_tx{
				margin-left: auto;
				width: 40rpx;
				height: 40rpx;
			}
		}	
	}
	.nlist{
		padding: 20rpx;
		display: flex;
		flex-direction: column;
		.nitem{
			padding: 20rpx 25rpx;
			background: #FFFFFF;
			border-radius: 30rpx;
			.nione{
				display: flex;
				flex-direction: row;
				align-items: center;
				.tous{
					width: 81rpx;
					border-radius: 50%;
					height: 81rpx;
					margin-right: 15rpx;
				}
				.niright{
					width: 82%;
					display: flex;
					flex-direction: column;
					.rione{
						display: flex;
						flex-direction: row;
						align-items: center;
						.riname{
							max-width: 80%;
							display: inline-block;
							font-weight: bold;
							font-size: 32rpx;
							color: #333333;
						}
						.hyuan{
							width: 80rpx;
							height: 32rpx;
							background: linear-gradient(-90deg, #272727, #4D4D4D);
							border-radius: 6rpx;
							display: flex;
							align-items: center;
							justify-content: center;
							font-weight: 500;
							font-size: 22rpx;
							color: #FFFFFF;
							margin-left: 10rpx;
						}
						.idname{
							font-weight: 400;
							font-size: 24rpx;
							color: #999999;
						}
						.hui{
							margin-left: 40rpx;
						}

					}
					.mttwo{
						margin-top: 15rpx;
					}
				}
				.comm_icon_next{
					margin-left: auto;
					width: 24rpx;
					height: 24rpx;
				}
			}
			.zheview{
				border-top: 1rpx solid #eee;
				display: flex;
				flex-direction: column;
				margin-top: 20rpx;
				padding-top: 20rpx;
				.zheitem{
					display: flex;
					flex-direction: row;
					flex-wrap: wrap;
					.items{
						width: 50%;
						display: flex;
						flex-direction: row;
						align-items: center;
						margin-bottom: 10rpx;
						.ileft{
							font-weight: 500;
							font-size: 24rpx;
							color: #999999;
						}
						.ival{
							font-weight: 500;
							font-size: 26rpx;
							color: #333333;
						}
					}
				}
				.shengbtn{
					display: flex;
					flex-direction: row;
					justify-content: flex-end;
					padding: 0 20rpx 20rpx 0;
					.sbtn{
						padding: 15rpx 25rpx;
						background: #52443B;
						border-radius: 16rpx 16rpx 16rpx 16rpx;
						font-weight: bold;
						font-size: 28rpx;
						color: #FFFFFF;
						margin-left: 20rpx;
					}
				}
			}
		}
	}
	.botview{
		position: fixed;
		height: 120rpx;
		width: 100%;
		bottom: 0;
		background-color: #fff;
		z-index: 10;
		padding: 0 30rpx;
		display: flex;
		align-items: center;
		.tjia{
			width: 100%;
			height: 90rpx;
			background: #52443B;
			border-radius: 16rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			font-weight: bold;
			font-size: 28rpx;
			color: #FFFFFF;
		}
	}
	.menlist{
		padding:30rpx 22rpx;
	}
	.oitem{
		display: flex;
		flex-direction: column;
		background: #FFFFFF;
		border-radius: 20rpx;
		margin-bottom: 24rpx;
		padding: 30rpx;
		.ohead{
			display: flex;
			flex-direction: row;
			align-items: center;
			margin-bottom: 30rpx;
			.icon_sj{
				width: 30rpx;
				height: 30rpx;
				margin-right: 9rpx;
			}
			.dianname{
				max-width: 70%;
				display: inline-block;
				font-weight: bold;
				font-size: 28rpx;
				color: #272727;
			}
			.zt{
				font-weight: 500;
				font-size: 25rpx;
				color: #FF0050;
			}
		}
		.olist{
			display: flex;
			flex-direction: column;
			.onav{
				display: flex;
				flex-direction: row;
				margin-bottom: 20rpx;
				.tu{
					width: 150rpx;
					height: 150rpx;
					border-radius: 10rpx;
					margin-right: 20rpx;
				}
				.navright{
					width: 73%;
					display: flex;
					flex-direction: column;
					.navone{
						display: flex;
						flex-direction: row;
						margin-bottom: 10rpx;
						.bt{
							max-width: 80%;
							display: inline-block;
							font-weight: 500;
							font-size: 26rpx;
							color: #222222;
						}
						.btmiao{
							max-width: 80%;
							display: inline-block;
							font-weight: 500;
							font-size: 20rpx;
							color: #BBBBBB;
						}
						.jia{
							font-weight: bold;
							font-size: 26rpx;
							color: #1A1A1A;
						}
						.zheng{
							padding: 4rpx 20rpx;
							border-radius: 6rpx;
							border: 1px solid #999999;
							font-weight: 500;
							font-size: 20rpx;
							color: #999999;
						}
					}
					.mt{
						margin-top: auto;
					}
				}
			}
			.onav:last-child{
				margin-bottom: 0;
			}
			
		}
		.heview{
			display: flex;
			flex-direction: column;
			.hename{
				font-weight: 500;
				font-size: 24rpx;
				color: #666666;
				margin: 13rpx 0;
				display: flex;
				flex-direction: row;
				justify-content: flex-end;
			}
			.btn{
				padding: 10rpx 20rpx;
				border-radius: 10rpx;
				border: 1rpx solid #767676;
				font-weight: 500;
				font-size: 24rpx;
				color: #222222;
				margin-left: 20rpx;
				min-width: 140rpx;
				display: flex;
				align-items: center;
				justify-content: center;
			}
			.fukuan{
				background: #FF7C41;
				color: #fff;
				border: none;
			}
			.queren{
				background: #483C38;
				color: #fff;
				border: none;
			}
		}
	}
	.nodata{
		margin: 200rpx auto;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		.kzt_img_zwsj{
			width: 156rpx;
			height: 128rpx;

		}
		text{
			font-weight: 400;
			font-size: 28rpx;
			color: #808080;
			display: block;
			margin-top: 30rpx;
		}
	}
	.shengku{
		font-weight: 500;
		font-size: 28rpx;
		color: #999999;
		display: block;
		margin-top: 8rpx;
	}
	.tablei{
		padding: 10rpx 90rpx 8rpx;
		display: flex;
		flex-direction: row;
		
		.leiitem{
			height: 68rpx;
			background: #F3F3F3;
			border-radius: 34rpx;
			display: flex;
			flex-direction: row;
			width: 100%;
			.tabitem{
				width: 50%;
				height: 100%;
				position: relative;
				display: flex;
				align-items: center;
				justify-content: center;
				font-weight: bold;
				font-size: 32rpx;
				color: #666666;
			}
			.tactive{
				background: #52443B;
				border-radius: 34rpx;
				color: #fff;
			}
		}
	}
	.menitem{
                display: flex;
                flex-direction: row;
                align-items: center;
                background: #FFFFFF;
                border-radius: 24rpx;
                padding: 25rpx;
                margin: 0 30rpx 20rpx;
                .tu{
                    width: 180rpx;
                    height: 180rpx;
                    margin-right: 20rpx;
                    border-radius: 20rpx;
                }
                .menone{
                    display: flex;
                    flex-direction: column;
                    width: 68%;
                    // height: 100%;
                    .menhead{
                        display: flex;
                        flex-direction: row;
                        align-items: center;
                        .name{
                            font-weight: bold;
                            font-size: 32rpx;
                            color: #272727;
                        }
                        .yingye{
                            font-weight: 500;
                            font-size: 26rpx;
                            color: #24B924;
                        }
                        .yingtime{
                            font-weight: 500;
                            font-size: 26rpx;
                            color: #333333;
                            display: inline-block;
                            margin-left: 18rpx;
                        }
                        .icon_dw{
                            width:22rpx;
                            height: 24rpx;
                            margin-right: 8rpx;

                        }
                        .ju{
                            font-weight: 500;
                            font-size: 28rpx;
                            color: #1A1A1A;
                        }
                        .juli{
                            margin-left: 30rpx;
                            font-weight: 500;
                            font-size: 24rpx;
                            color: #999999;
                            display: inline-block;
                            max-width: 70%;
                        }
						.tiview{
							margin-left: auto;
							width: 200rpx;
							height: 68rpx;
							background: #52443B;
							border-radius: 16rpx 16rpx 16rpx 16rpx;
							display: flex;
							align-items: center;
							justify-content: center;
							font-weight: bold;
							font-size: 28rpx;
							color: #FFFFFF;
						}
                    }
                    .mennav{
                        margin-top: 35rpx;
                    }
                }
            }
        // }

		.popone{
        width: 100%;
        background: #FFFFFF;
        border-radius: 30rpx;
        // height: 530rpx;
        .bg{
            position: absolute;
            width: 100%;
            height: 300rpx;
            border-radius: 30rpx 30rpx 0 0 ;
        }
        .icon_gbcha{
            width: 40rpx;
            height: 40rpx;
            margin-left: auto;
            position: absolute;
            right: 30rpx;
            top: 30rpx;
        }
        .yuedu{
            height: 80rpx;
            display: flex;
            padding: 0 30rpx;
            align-items: center;
            .icon_xz_n{
                width: 36rpx;
                height: 36rpx;
                margin-right: 8rpx;
            }
            .xy{
                font-weight: 500;
                font-size: 20rpx;
                color: #999999;
                display: block;
                width: 90%;
            }
            .xyhu{
                color: rgba(234, 89, 24, 1);
            }
        }
        .kaolv{
            font-weight: bold;
            font-size: 28rpx;
            color: #666666;
            display: block;
            text-align: center;
            margin-top: 20rpx;
        }
        .phonenav{
            position: relative;
            // margin: 30rpx;
            display: flex;
            flex-direction: column;
            // justify-content: center;
            align-items: center;
            padding: 40rpx 30rpx;
            .img_aq{
                width: 173rpx;
                height: 211rpx;
                margin-bottom: 20rpx;
            }
            .jiename{
                font-weight: bold;
                font-size: 36rpx;
                color: #111111;
            }
            .queren{
                font-weight: 400;
                font-size: 24rpx;
                color: #666666;
                display: block;
                margin: 40rpx 0 80rpx;
            }
            .chaka{
                padding: 30rpx;
                width: 100%;
                display: flex;
                flex-direction: column;
                align-items: center;
                justify-content: center;
                background: #F6F7F9;
                border-radius: 16rpx;
                margin: 25rpx 0;
                .chaname{
                    font-weight: bold;
                    font-size: 28rpx;
                    color: #111111;
                }
                .phonenum{
                    display: block;
                    font-weight: bold;
                    font-size: 50rpx;
                    color: #F06047;
                    margin: 10rpx 0;
                }
                .xiugai{
                    display: flex;
                    flex-direction: row;
                    align-items: center;
                    .noben{
                        font-weight: 400;
                        font-size: 24rpx;
                        color: #666666;
                    }
                    .xiu{
                        font-weight: 400;
                        font-size: 24rpx;
                        color: #F06047;
                        display: inline-block;
                        margin-left: 6rpx;
                    }
                }
            }
            .dianbtn{
                height: 90rpx;
                background: linear-gradient(90deg, #FF8F39, #FF4D43);
                border-radius: 45rpx;
                display: flex;
                flex-direction: column;
                align-items: center;
                justify-content: center;
                width: 100%;
                margin-top: 20rpx;
                .bm{
                    font-weight: bold;
                    font-size: 28rpx;
                    color: #FFFFFF;
                }
                .bmmaio{
                    font-weight: 500;
                    font-size: 20rpx;
                    color: #FFFFFF;
                }
            }
            .bzhang{
                display: flex;
                flex-direction: row;
                align-items: center;
                margin-top: 30rpx;
                .icon_ts{
                    margin-right: 6rpx;
                    width: 24rpx;
                    height: 24rpx;
                }
                .zhiname{
                    font-weight: 400;
                    font-size: 20rpx;
                    color: #F06047;
                }
            }
        }
    }
    .kmiao{
        font-weight: 500;
        font-size: 28rpx;
        color: #111111;
        display: block;
        margin: 40rpx 0 20rpx;
    }
    .renxie{
        font-weight: 500;
        font-size: 28rpx;
        color: #FF8C39;
        display: block;
        margin-bottom: 50rpx;
    }
    .img_cg{
        width: 140rpx;
        height: 140rpx;
        margin-bottom: 15rpx;
    }
    .yikai{
        font-weight: bold;
        font-size: 36rpx;
        color: #111111;
    }
    .kaiti{
        background: #E9FFEB;
        border-radius: 6rpx;
        display: flex;
        flex-direction: column;
        width: 100%;
        margin: 20rpx 0 15rpx;
        padding:20rpx 10rpx;
        .kaione{
            display: flex;
            flex-direction: row;
            align-items: center;
            .icON_bz{
                margin-right: 7rpx;
                width: 24rpx;
                height: 24rpx;
            }
            .jianame{
                font-weight: bold;
                font-size: 28rpx;
                color: #16B925;
            }
        }
        .youxiao{
            font-weight: 500;
            font-size: 20rpx;
            color: #16B925;
            display: block;
            margin-top: 10rpx;
        }
    }
	.queli{
        display: flex;
        flex-direction: column;
        border: 1rpx solid #333;
		padding:8rpx 20rpx;
		width: 100%;
		border-radius: 20rpx;
		margin: 40rpx 0;
        .queitem{
            display: flex;
            flex-direction: row;
            align-items: center;
            width: 100%;
            .icon_xz_s{
                margin-right: 15rpx;
                width: 36rpx;
                height: 36rpx;
            }
            text{
                font-weight: 500;
                font-size: 28rpx;
                color: #111111;
            }
        }
    }
</style>
